from bs4 import BeautifulSoup
import requests
import pymysql

d1 = {}
# conn = pymysql.connect(
#             host="localhost",
#             user="root",
#             password="keywords",
#             charset="utf8mb4",
#             database="memeda"
#         )
# cursor = conn.cursor()

dow = requests.get("https://movie.douban.com/cinema/nowplaying/chengdu/")
dow.encoding = dow.apparent_encoding
gg = dow.text
soup = BeautifulSoup(gg, "html.parser")
news = soup.find_all('a', {'class': 'ticket-btn',
                           'data-psource': 'title'
                           })
score = soup.find_all('li',{'class':'srating'})
for i in news:
    gg = i.text.strip()
    d1 = {'title': gg}
    print(gg)

for v in score:
    gg = v.text
    d1 = {'score': gg}
    # print(gg)
# print(d1)
sql = 'insert into douban (`title`,`score`)values("{}","{}")'.format(d1.get("title",""),d1.get("score",""))
print(sql)
# cursor.execute(sql)
# conn.commit()
# cursor.close()